package org.redis.cluster.admin.slot.service;

import java.util.ArrayList;
import java.util.Collection;

import org.redis.cluster.admin.slot.model.SlotInfo;
import org.redis.cluster.loadbalance.slot.SlotManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SlotService {

	@Autowired
	private SlotManager slotManager;
	
	/**
	 * @return
	 */
	public int getSlotCount() {
		return slotManager.getSlotCount();
	}
	
	/**
	 * 返回info
	 * @return
	 */
	public Collection<SlotInfo> getInfos() {
		int count=getSlotCount();
		Collection<SlotInfo> infos=new ArrayList<SlotInfo>(count);
		
		for(int i=0;i<count;i++) {
			String clientId=slotManager.getSlotClientId(i);
			SlotInfo info=new SlotInfo();
			info.setIndex(i);
			info.setClientId(clientId);
			infos.add(info);
		}
		
		return infos;
	}
}